# encoding=utf-8
import time
import unittest
from unittestreport import TestRunner
from config.read_config import Config
from executionTestcases.test_cases import All
from settings.settings import Route

if __name__ == '__main__':
    server = Config().read(Route().config('router.ini'), 'email', 'server')
    port = Config().read(Route().config('router.ini'), 'email', 'port')
    sender = Config().read(Route().config('router.ini'), 'email', 'sender')
    password = Config().read(Route().config('router.ini'), 'email', 'password')
    receiver = Config().read(Route().config('router.ini'), 'email', 'receiver')
    suite = unittest.TestSuite()
    loader = unittest.TestLoader()
    cases = (loader.loadTestsFromTestCase(All))
    suit = unittest.TestSuite(cases)
    now = time.strftime('%Y-%m-%d %H_%M_%S')
    filename = 'report-' + now + '.result.html'
    runner = TestRunner(suite=suit, filename=filename,
                        report_dir=Route().report(),
                        title='dataDrivenApiFrameWork', templates=2,
                        tester='Joymon', desc='dataDrivenApiFrameWork')
    runner.run()
    runner.send_email(server, int(port), sender, password,receiver)
